using UnityEngine;
using System.Collections;

public class cKeyMove : MonoBehaviour {
	
	public float max_speed = 30.0f;
	
	public float speed = 3.0f;
	
	public float accelate = 0.5f;
	
	public float max_accelate = 2f;
	
	public float rotateSpeed = 60.0f;
	
	public cCar currentCar = null;
	
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
		
		bool bAcc = false;
	
/*		if ( currentCar.bCrash )
		{
			//speed = 0f;
		}
		else*/
		{
		
			if ( Input.GetKey( KeyCode.W ) )
			{
				bAcc = true;
				speed += accelate;
				if ( max_speed < speed ) speed = max_speed;
			}
			
			if ( Input.GetKey( KeyCode.S ) )
			{
				bAcc = true;
				speed -= 1.19f;
				if ( speed < -10f )
					speed = -10f;
			}
			
			if ( Input.GetKey( KeyCode.A ) )
			{
				
				if ( speed != 0f )
					transform.Rotate(Vector3.up * -rotateSpeed* Time.deltaTime);
				
			}
			if ( Input.GetKey( KeyCode.D ) )
			{
				
				if ( speed != 0f )
					transform.Rotate(Vector3.up * rotateSpeed* Time.deltaTime);
				
			}
			
		}
		
		if ( !bAcc )
		{
			
			if ( speed > 0 )
			{
				
				speed -= .19f;
				if ( speed < 0f )
					speed = 0f;
				
			}
			else
			{
			
				speed += .19f;
				if ( speed > 0f )
					speed = 0f;
			}
		}

		transform.Translate(Vector3.forward * speed * Time.deltaTime);
		
	}
	
}
